import { createStore } from 'vuex';

const store = createStore({
    state: {
        user: null,
        menus: [],
        permissionCodes: '',
        token: null
    },
    mutations: {
        setUser(state, user) {
            state.user = user;
        },
        setMenus(state, menus) {
            state.menus = menus;
        },
        setPermissionCodes(state, permissionCodes) {
            state.permissionCodes = permissionCodes;
        },
        setToken(state, token) {
            state.token = token;
        }
    },
    actions: {
        updateUser({ commit }, user) {
            commit('setUser', user);
        },
        updateMenus({ commit }, menus) {
            commit('setMenus', menus);
        },
        updatePermissionCodes({ commit }, permissionCodes) {
            commit('setPermissionCodes', permissionCodes);
        },
        updateToken({ commit }, token) {
            commit('setToken', token);
        }
    },
    getters: {
        getUser: state => state.user,
        getMenus: state => state.menus,
        getPermissionCodes: state => state.permissionCodes,
        getToken: state => state.token
    }
});

export default store;